package com.red.wood.module.area;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/area")
public class AreaInfoController {

private static final Log log = LogFactory.getLog(AreaInfoController.class);
	
	@GetMapping(value = "/area_json.json")
	public String getActiveUrlData(HttpServletRequest request, HttpServletResponse response) {
		String returnInfo = "";
		try {
			response.setHeader("Access-Control-Allow-Origin", "*"); 
			returnInfo = IOUtils.toString(AreaInfoController.class.getClassLoader().getResourceAsStream("area_json.json"),"UTF-8");
		}catch(Exception e) {
			if(log.isErrorEnabled()) {
				log.error(e.getMessage(),e);
			}
		}
		return returnInfo;
	}
	
	@GetMapping(value = "/china.top.new.json")
	public String getChinaInfo(HttpServletRequest request, HttpServletResponse response) {
		String returnInfo = "";
		try {
			response.setHeader("Access-Control-Allow-Origin", "*"); 
			returnInfo = IOUtils.toString(AreaInfoController.class.getClassLoader().getResourceAsStream("china.top.new.json"),"UTF-8");
		}catch(Exception e) {
			if(log.isErrorEnabled()) {
				log.error(e.getMessage(),e);
			}
		}
		return returnInfo;
	}
	
	@GetMapping(value = "/360000_full.json")
	public String getJxFull(HttpServletRequest request, HttpServletResponse response) {
		String returnInfo = "";
		try {
			response.setHeader("Access-Control-Allow-Origin", "*"); 
			returnInfo = IOUtils.toString(AreaInfoController.class.getClassLoader().getResourceAsStream("360000_full.json"),"UTF-8");
		}catch(Exception e) {
			if(log.isErrorEnabled()) {
				log.error(e.getMessage(),e);
			}
		}
		return returnInfo;
	}
	
	@GetMapping(value = "/china.json")
	public String mapTopoJson(HttpServletRequest request, HttpServletResponse response) {
		String returnInfo = "";
		try {
			response.setHeader("Access-Control-Allow-Origin", "*"); 
			returnInfo = IOUtils.toString(AreaInfoController.class.getClassLoader().getResourceAsStream("china.json"),"UTF-8");
		}catch(Exception e) {
			if(log.isErrorEnabled()) {
				log.error(e.getMessage(),e);
			}
		}
		return returnInfo;
	}
}
